<?php

namespace App\Http\Controllers;

use App\Facades\WxMarketing;
use App\Http\Response\CreatedResponse;
use Illuminate\Http\Request;
use Laravel\Lumen\Routing\Controller as BaseController;

class StudentActionsStatisticsController extends BaseController
{
    public function create(Request $request)
    {
        $this->validate($request, [
            'socialType' => 'required|in:"wx-jqfx","wx-jqkid"',
            'setId' => 'required|integer',
            'clickId' => 'required|string',
            'url' => 'required|url',
            'actionParam' => 'array',
            'actionType' => 'in:COMPLETE_ORDER,RESERVATION',
        ]);
        $studentId = intval($request->header("X-Authenticated-Userid"));
        WxMarketing::addAction(
            $request->input('socialType'),
            intval($request->input('setId')),
            $request->input('url'),
            $request->input('clickId'),
            array_merge($request->input('actionParam', []), [ 'studentId' => $studentId ]),
            $request->input('actionType', 'COMPLETE_ORDER')
        );

        return new CreatedResponse();
    }
}
